﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using System.IO;
using Intorise.Common;

namespace Model
{
    public class BotConfig : Config.AbstractConfig
    {
        public int HP0 { get; set; }
        public int HP1 { get; set; }
        public int HP2 { get; set; }
        public int MP0 { get; set; }
        public int MP1 { get; set; }
        public int MP2 { get; set; }
        /// <summary>
        /// 移除怪物距离
        /// </summary>
        public int RemoveMonsterDistance { get; set; }
        /// <summary>
        /// 拾取物品距离
        /// </summary>
        public int GetItemDistance { get; set; }
        /// <summary>
        /// 登录超时(秒)
        /// </summary>
        public int TimeoutLogin { get; set; }
        /// <summary>
        /// 移动超时(秒)
        /// </summary>
        public int TimeoutMove { get; set; }
        /// <summary>
        /// 杀怪数检测时间(秒)
        /// </summary>
        public int TimeoutKilledCount { get; set; }
        /// <summary>
        /// 服务器线
        /// </summary>
        public int LineNumber { get; set; }
        /// <summary>
        /// 使用随机线
        /// </summary>
        public bool RandomLine { get; set; }
        /// <summary>
        /// 登录间隔(秒)
        /// </summary>
        public int LoginInteravl { get; set; }
        /// <summary>
        /// 黑龙波技能CD
        /// </summary>
        public double HLBCD { get; set; }
        /// <summary>
        /// 最大尝试登录次数
        /// </summary>
        public int MaxLoginCount { get; set; }
        /// <summary>
        /// 状态检测间隔
        /// </summary>
        public int CheckStatusInteravl { get; set; }
        /// <summary>
        /// 数据刷新间隔
        /// </summary>
        public int RefreshInteravl { get; set; }
        /// <summary>
        /// 需要拾取的物品名称
        /// </summary>
        public string NeedPickupItems { get; set; }
        /// <summary>
        /// 只捡指定物品
        /// </summary>
        public bool OnlyPickupSpecify { get; set; }
        /// <summary>
        /// 卖东西时保留物品包含的文本
        /// </summary>
        public string SellExcepet { get; set; }
        /// <summary>
        /// 自动提炼
        /// </summary>
        public bool AutoTL { get; set; }

        public BotConfig()
        {
            fileName = "BotConfig.config";
        }

        public override void Load()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(BotConfig));
            FileStream stream = null;
            if (!File.Exists(fileName))
            {
                this.HP0 = 1000;
                this.HP1 = 1700;
                this.HP2 = 5000;
                this.MP0 = 70;
                this.MP1 = 50;
                this.MP2 = 30;
                this.RemoveMonsterDistance = 14;
                this.GetItemDistance = 2;
                this.TimeoutMove = 15;
                this.TimeoutLogin = 30;
                this.TimeoutKilledCount = 30;
                this.LineNumber = 1;
                this.RandomLine = false;
                this.LoginInteravl = 20;
                HLBCD = 1;
                MaxLoginCount = 10;
                CheckStatusInteravl = 60;
                RefreshInteravl = 5;
                NeedPickupItems = "生命宝石, 玛雅之石, 灵魂宝石, 金币,祝福宝石, 小型治疗药水, 中型治疗药水, 大型治疗药水,小型魔力药水, 中型魔力药水, 大型魔力药水";
                SellExcepet = "卓越,《十》,《年》,《经》,《典》,《MU 》,魔法结晶,创造宝石";
                this.DontPickupItems = "";
                this.OnlyPickupSpecify = true;
                this.AutoTL = false;
                Save();
            }
            try
            {
                stream = File.Open(fileName, FileMode.Open);
                var config = (BotConfig)serializer.Deserialize(stream);
                this.HP0 = config.HP0;
                this.HP1 = config.HP1;
                this.HP2 = config.HP2;
                this.MP0 = config.MP0;
                this.MP1 = config.MP1;
                this.MP2 = config.MP2;
                this.RemoveMonsterDistance = config.RemoveMonsterDistance;
                this.GetItemDistance = config.GetItemDistance;
                this.TimeoutMove = config.TimeoutMove;
                this.TimeoutLogin = config.TimeoutLogin;
                this.TimeoutKilledCount = config.TimeoutKilledCount;
                this.LineNumber = config.LineNumber;
                this.RandomLine = config.RandomLine;
                this.LoginInteravl = config.LoginInteravl;
                this.HLBCD = config.HLBCD;
                MaxLoginCount = config.MaxLoginCount;
                CheckStatusInteravl = config.CheckStatusInteravl;
                RefreshInteravl = config.RefreshInteravl;
                NeedPickupItems = config.NeedPickupItems;
                this.OnlyPickupSpecify = config.OnlyPickupSpecify;
                this.SellExcepet = config.SellExcepet;
                this.AutoTL = config.AutoTL;
                this.DontPickupItems = config.DontPickupItems;
            }
            catch (Exception ex)
            {
                ConsoleBLL.WriteLineError("加载配置数据出错！\r\n" + ex.Message);
            }
            finally
            {
                if (stream != null) { stream.Close(); }
            }
        }

        public string DontPickupItems { get; set; }
    }
}
